﻿<%@ Page Title="" Language="C#" MasterPageFile="~/WebmasterTool/Admin.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Framework.WebmasterTool.Questions.Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
            $("#chkAll").live("change", function () {
                if ($(this).is(":checked")) {
                    $(".checkbox").attr("checked", "checked");
                }
                else {
                    $(".checkbox").removeAttr("checked");
                }
            });
            $(".checkbox").live("click", function () {
                var allCheck = true;
                $(".checkbox").each(function () {
                    if (!$(this).is(":checked")) {
                        allCheck = false;
                        return;
                    }
                });
                if (allCheck == true) {
                    $("#chkAll").attr("checked", "checked");
                }
                else {
                    $("#chkAll").removeAttr("checked");
                }
            });
            $("#<%= btnDelete.ClientID %>").live("click", function () {
             var callFrom = $(this);
             jConfirm('Chắc chắn xoá?', 'Digisky Confirm Dialog',
             function (r) {
                 if (r) {
                     __doPostBack(callFrom.attr('name').replace(/_/g, '$'), '');
                 }
             });
             return false;
         });
         // change IsApproved
         $(".IsApproved").click(function () {
             var callFrom = $(this);
             jConfirm('Chắc chắn thay đổi?', 'Digisky Confirm Dialog',
             function (r) {
                 if (r) {
                     var ArticleID = callFrom.attr("data-id");
                     var IsApproved = callFrom.attr("data-bool");
                     if (IsApproved == "0") {
                         IsApproved = 1;
                         callFrom.attr("data-bool", "1");
                         callFrom.html("Duyệt");
                     }
                     else {
                         IsApproved = 0;
                         callFrom.attr("data-bool", "0");
                         callFrom.html("Chưa duyệt");
                     }
                     $.ajax({
                         type: "POST",
                         url: "Default.aspx/UpdateIsApproved",
                         data: JSON.stringify({ ArticleID: ArticleID, IsApproved: IsApproved }),
                         contentType: "application/json; charset=utf-8",
                         async: false,
                         dataType: "json",
                         success: function (response) {
                         },
                         error: function (xhr, ajaxOptions, thrownError) {
                             jAlert(thrownError);
                         }
                     });
                 }
             });
         });
         // change displayorder
         $("#<%= btnUpdate.ClientID %>").click(function () {
                var total = $('.DisplayOrder').length;
                var LstArticleID = "";
                var LstDisplayOrder = "";
                jConfirm('Chắc chắn thay đổi?', 'Digisky Confirm Dialog',
                function (r) {
                    if (r) {
                        $('.DisplayOrder').each(function (index) {
                            if (index === total - 1) {
                                LstArticleID += $(this).attr("data-id");
                                LstDisplayOrder += $(this).val();
                            }
                            else {
                                LstArticleID += $(this).attr("data-id") + ",";
                                LstDisplayOrder += $(this).val() + ",";
                            }
                        });
                        $.ajax({
                            type: "POST",
                            url: "Default.aspx/UpdateDisplayOrder",
                            data: JSON.stringify({ LstArticleID: LstArticleID, LstDisplayOrder: LstDisplayOrder }),
                            contentType: "application/json; charset=utf-8",
                            async: false,
                            dataType: "json",
                            success: function (response) {
                            },
                            error: function (xhr, ajaxOptions, thrownError) {
                                jAlert(thrownError);
                            }
                        });
                    }
                });
                return false;
            });
     });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ctlCaption" runat="server">
    Quản lý câu hỏi
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PageContent" runat="server">
    <asp:Label ID="lblPermissionMessage" runat="server" Font-Bold="true" ForeColor="Red"
        Text="Tài khoản không có quyền truy cập vào trang này" Visible="false"></asp:Label>
    <asp:Panel ID="Panel1" runat="server" Visible="true">
        <table align="center" width="785" cellpadding="0" cellspacing="0" border="0">
            <tr>
                <td>
                    <table width="785" align="center" cellpadding="0" cellspacing="0" border="0">
                        <tr>
                            <td align="right">
                                <asp:Button ID="btnNew" runat="server" Text="Thêm bài viết mới" Style="float: left;"
                                    OnClick="btnNew_Click" />
                                <span style="font-weight: bold">Tìm bài viết : </span>
                                <asp:TextBox runat="server" ID="txtKeyword"></asp:TextBox>
                                <asp:DropDownList runat="server" ID="ddlCategories" Width="150px" AppendDataBoundItems="true">
                                    <asp:ListItem Text="[Tất cả]" Value="0"></asp:ListItem>
                                </asp:DropDownList>
                                <asp:Button runat="server" ID="btnSearch" Text="Tìm kiếm" OnClick="btnSearch_Click" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td align="center" style="padding-top: 10px;">
                    <asp:GridView runat="server" Width="785" ID="grvArticles" CssClass="grid" AutoGenerateColumns="false"
                        AllowPaging="true" PageSize="10" AllowSorting="true" ToolTip="all" OnSorting="grvArticles_Sorting"
                        OnDataBinding="grvArticles_DataBinding" OnPageIndexChanging="grvArticles_PageIndexChanging">
                        <Columns>
                            <asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="20px" HeaderStyle-Width="20px">
                                <HeaderTemplate>
                                    <input id="chkAll" type="checkbox" />
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <input id="chkSelect" runat="server" class="checkbox" type="checkbox" title='<%# Eval("ID") %>' />
                                </ItemTemplate>
                                <HeaderStyle Width="20px" />
                                <ItemStyle HorizontalAlign="Center" Width="20px" />
                            </asp:TemplateField>                            
                            <asp:TemplateField HeaderText="Tiêu đề" SortExpression="Title" HeaderStyle-HorizontalAlign="Left"
                                ItemStyle-HorizontalAlign="left">
                                <ItemTemplate>
                                    <asp:HyperLink ID="hplArticleEdit" runat="server" NavigateUrl='<%# "QuestionAdd.aspx?ID=" + Eval("ID") %>'
                                        Text='<%# Eval("Title") %>'></asp:HyperLink>
                                </ItemTemplate>
                            </asp:TemplateField>                            
                            <asp:TemplateField HeaderText="Ngày tạo" SortExpression="AddedDate" HeaderStyle-Width="90"
                                ItemStyle-Width="90" HeaderStyle-HorizontalAlign="center" ItemStyle-HorizontalAlign="center">
                                <ItemTemplate>
                                    <asp:HiddenField ID="hdfAddedDate" runat="server" Value='<%# Eval("DateCreate") %>' />
                                    <asp:Label ID="lblAddedDate" runat="server" Text='<%# String.Format("{0:dd/MM/yyyy HH:mm:ss tt}", (DateTime)(Eval("DateCreate")))%>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                             <asp:TemplateField HeaderText="Vị trí" SortExpression="DisplayOrder" HeaderStyle-Width="50"
                                ItemStyle-Width="50" HeaderStyle-HorizontalAlign="center" ItemStyle-HorizontalAlign="center">
                                <ItemTemplate>
                                    <%--<asp:Label ID="lblDisplayOrder" runat="server" Text='<%# Eval("DisplayOrder") %>'></asp:Label>--%>
                                    <input class="DisplayOrder" type="text" data-id="<%# Eval("ID") %>" value="<%# Eval("DisplayOrder") %>" style="width: 30px; text-align: center;" />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <EmptyDataTemplate>
                            <table align="center" width="300" border="0">
                                <tr>
                                    <td height="50" align="center">
                                        <div align="center">
                                            Không có dữ liệu
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </EmptyDataTemplate>
                        <PagerSettings Mode="NumericFirstLast" />
                    </asp:GridView>
                </td>
            </tr>
            <tr>
                <td align="left">
                    <br />
                    <asp:Button runat="server" ID="btnDelete" Text="Xoá các tin đã chọn" OnClick="btnDelete_Click" />
                    <asp:Button runat="server" ID="btnUpdate" Text="Cập nhật vị trí" Style="float: right;" />
                </td>
            </tr>
        </table>
    </asp:Panel>
</asp:Content>
